package cn.laixueit.cart.controller;

import cn.laixueit.cart.service.GoodsCreateHtml;
import cn.laixueit.cart.service.GoodsWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.FileNotFoundException;
import java.util.Map;

@Controller
@RequestMapping("/item")
public class GoodsWebController {

    @Autowired
    private GoodsWebService goodsWebService;
    @Autowired
    private GoodsCreateHtml createHtml;

    @GetMapping("/{id}.html")
    public String createHtml(@PathVariable("id")Long id, Model model){
        Map<String, Object> map = goodsWebService.loadData(id);

        model.addAllAttributes(map);

        try {
            createHtml.createHtml(id);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return "item";
    }
}
